
uniform mat4 matrix_projection;
uniform mat4 matrix_view;
uniform mat4 matrix_world;

struct Material
{
	vec4 ambient;
	vec4 diffuse;
	vec4 specular;
	float shininess;
	vec4 emission;
};

struct Light
{
	vec4 ambient;
	vec4 diffuse;
	vec4 specular;
	vec4 position;
	float range;
};

vec4 calc_phong_lighting (Light light, Material material, vec3 position, vec3 normal);

uniform Material material;
uniform Light light;

attribute vec4 vertices;
attribute vec3 normals;
attribute vec4 texcoords;

mat4 matrix_modelviewprojection = matrix_projection * matrix_view * matrix_world;

varying vec2 tex_coord;
varying vec4 color;
varying vec4 screen_coord;

void main(void)
{
    tex_coord = texcoords.xy;

    vec3 normal = (matrix_world * vec4 (normals, 0.0)).xyz;

    vec3 position = (matrix_world * vertices).xyz;
    color = calc_phong_lighting (light, material, position, normal);

    gl_Position = matrix_modelviewprojection * vertices;

    screen_coord = gl_Position;

}
